//
//  LTProfileDetailController.m
//  LTChat
//
//  Created by 俊松何 on 2017/7/20.
//  Copyright © 2017年 俊松何. All rights reserved.
//

#import "LTProfileDetailController.h"
//#import "LTSetBeizhuController.h"
#import "LTSelectPhotoView.h"
#import "LTAvatarViewController.h"
#import "LTSignatureController.h"
@interface LTProfileDetailController ()<LTContactManagerDelegate,LTSelectPhotoViewDelegate>
@property(nonatomic,strong) LTSelectPhotoView *selectphotoView;

/** 选择的图片 */
@property (nonatomic, strong) UIImagePickerController *imagePickerVc;

@property(nonatomic,strong) UIImage *selectImage;

@property (weak, nonatomic) IBOutlet UILabel *avatertipLable;
@property (weak, nonatomic) IBOutlet UILabel *nicktipLable;
@property (weak, nonatomic) IBOutlet UILabel *myqrcodetipLable;
@property (weak, nonatomic) IBOutlet UILabel *sextipLable;
@property (weak, nonatomic) IBOutlet UILabel *signatertipLable;


@property (weak, nonatomic) IBOutlet UIImageView *avaterImageView;
@property (weak, nonatomic) IBOutlet UILabel *nickLable;
@property (weak, nonatomic) IBOutlet UILabel *sixLable;
@property (weak, nonatomic) IBOutlet UILabel *signaterLable;


@end

@implementation LTProfileDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = NSLTLocalizedString(@"personInfo.title", nil);
    [self yd_addSubviews];
    [self curentUserInfoChange];
    
    @weakify(self);
    [[[NSNotificationCenter defaultCenter] rac_addObserverForName:UserInfoChange object:nil] subscribeNext:^(NSNotification * _Nullable x) {
        @strongify(self);
        [self curentUserInfoChange];
    }];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

-(void)goBack
{
    [[LTClient sharedClient].contactManager removeDelegate:self];
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)dealloc
{
   
}


#pragma mark LTContactManagerDelegate
- (void)curentUserInfoChange;
{
    [self.avaterImageView sd_setImageWithURL:[NSURL URLWithString:[LTClient sharedClient].currentUser.avatar] placeholderImage:defaultImgae];
    self.nickLable.text = [LTClient sharedClient].currentUser.name;
    self.signaterLable.text = [LTClient sharedClient].currentUser.signature;
    self.sixLable.text = [[LTClient sharedClient].currentUser getGenderStr];
    [self.tableView reloadData];
}



-(void)yd_layoutNavigation
{
    self.title = NSLTLocalizedString(@"personInfo.title", nil);
}
-(void)yd_addSubviews
{
    self.avatertipLable.text = NSLTLocalizedString(@"personInfo.avatar", nil);
    self.nicktipLable.text = NSLTLocalizedString(@"personInfo.nickname", nil);
    self.myqrcodetipLable.text = NSLTLocalizedString(@"personInfo.myQRCode", nil);
    self.sextipLable.text = NSLTLocalizedString(@"personInfo.gender", nil);
    self.signatertipLable.text = NSLTLocalizedString(@"personInfo.signature", nil);
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if(indexPath.section == 0)
    {
        switch (indexPath.row) {
            case 0: {
                LTAvatarViewController *Vc = [[LTAvatarViewController alloc] init];
                [self.navigationController pushViewController:Vc animated:YES];
            }break;
            case 1:
            {
//                LTSetBeizhuController *changenameVc = [[LTSetBeizhuController alloc] init];
//                changenameVc.isChangeNickName = YES;
//                [self.navigationController pushViewController:changenameVc animated:YES];
            }break;
            case 2:
            {
//                LTMyQRController *qrVc = [[LTMyQRController alloc] init];
//                [self.navigationController pushViewController:qrVc animated:YES];
            }break;
            default:break;
        }
    }else if (indexPath.section == 1)
    {
        if(indexPath.row == 0)
        {
//            [self.selectphotoView show];
        }else if (indexPath.row == 1)
        {
            LTSignatureController *vc = [[LTSignatureController alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0)
    {
        return 1;
    }else
    {
         return 10;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}



-(LTSelectPhotoView *)selectphotoView
{
    if(_selectphotoView == nil)
    {
        _selectphotoView = [LTSelectPhotoView ltselectView];
        _selectphotoView.isGender = YES;
        _selectphotoView.delegate = self;
    }
    return _selectphotoView;
}


-(void)selectGrilViewSelectPhoto:(LTSelectPhotoView *)view
{
  
    [MBProgressHUD showProcessHud:NSLTLocalizedString(@"main.loding", nil) toView:self.view];
    [[LTClient sharedClient].contactManager updateCurrentUserInfoGender:2 completion:^(LTError *ltrror) {
        [MBProgressHUD hideHUDForView:self.view];
        
    }];
}

-(void)selectBoyViewSelectPhoto:(LTSelectPhotoView *)view
{
    [MBProgressHUD showProcessHud:NSLTLocalizedString(@"main.loding", nil) toView:self.view];
    [[LTClient sharedClient].contactManager updateCurrentUserInfoGender:1 completion:^(LTError *ltrror) {
        [MBProgressHUD hideHUDForView:self.view];
        
    }];
    
}

@end
